<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fns" uri="/WEB-INF/tlds/fns.tld" %>
<%@ taglib prefix="shiro" uri="/WEB-INF/tlds/shiros.tld" %>
<c:set var="path" value="${pageContext.request.contextPath}"/>

<style>
    .panel .form-group{ position: relative;}
    .clear:after{content:'';display:block;clear:both;}
    .clear{zoom:1;}
    .addcailiao{position:fixed;right:30px;bottom:220px;}
    .ht_in_jia{background:#f63;color: white;}
    .formspan{text-align: right;}
    .ht_in_jian{ border:none;padding: 0px 10px;fot-size:18px;color: white;background: #f63;position: absolute;
        right:60px;
        top:2px;}
</style>
<!-- Content Header (Page header) -->
<section class="content-header" style="">
    <h1>
        档案库
        <small>档案库</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> 主页</a></li>
        <%--<li><a href="#">业务管理</a></li>--%>
        <li class="active">档案库</li>
    </ol>
</section>

<section class="content">
    <div class="row">
       <%-- <ul class="nav nav-tabs">
            <li><a href="#" onclick="loadHref('#archives/archives_user')">档案库</a></li>
            <li class="active"><a href="#">档案库管理</a></li>
        </ul>--%>
        <div class="col-xs-12">
            <div class="box">
                <!-- /.box-header -->
                <div class="box-body">
                    <p id="toolbar">
                    <form class="form-inline">
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">名称</div>
                                <input type="text" class="form-control" name="comName" id="comName_id"
                                       placeholder="关键字...">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">业务类型</div>
                                <select class="form-control" name="comType" id="comType_id">
                                    <option value="">请选择</option>
                                    <option value="1">供应链融资</option>
                                    <option value="2">企业经营贷</option>
                                    <option value="3">个人借款</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">所处阶段</div>
                                <select class="form-control" name="status" id="status_id">
                                    <option value="">请选择</option>
                                    <option value="1">待尽调</option>
                                    <option value="2">待部门审核</option>
                                    <option value="3">待风控审核</option>
                                    <option value="4">待上线</option>
                                    <option value="5">贷后管理</option>
                                    <option value="6">存档</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label>录入日期:</label>
                            <div class="input-group date">
                                <div class="input-group-addon">
                                    <i class="fa fa-calendar"></i>
                                </div>
                                <input type="text" class="form-control pull-right" id="datepicker">
                            </div>
                        </div>
                        <button type="button" class="btn btn-primary queryButton">查询</button>
                    </form>
                    <table id="table"></table>
                </div>

                <!-- /.box-body -->
            </div>
            <!-- /.box -->
        </div>

    </div>
    <!-- /.row -->
</section>
<!-- /.content -->

<!-- add Modal -->
<div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="addModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close" id="closeId1"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="addModalLabel">添加担保信息</h4>
            </div>
            <div class="modal-body">
                <form  action="#" id="addCompanyInfo">
                    <input type="hidden" id="compay_id" name="id" readonly required>

                    <div class="form-group">
                        <label for="com_name" class="control-label"><span class="asterisk">*</span>名称</label>
                        <input id="com_name" type="text" class="form-control" name="comName" placeholder="担保人名称" minlength="1" required>
                        <div class="help-block with-errors"></div>
                    </div>
                    <div class="form-group">
                        <label for="comType" class="control-label"><span class="asterisk">*</span>类别:</label>
                        <select name="comType" id="comType" class="form-control chosen-select"
                                data-placeholder="请选择类别" onchange="comTypeChange()" required>
                            <option value="4">企业担保</option>
                            <option value="5">个人担保</option>
                        </select>
                        <div class="help-block with-errors"></div>
                    </div>
                    <div class="form-group">
                        <label for="credit_line" class="control-label">担保金额</label>
                        <input id="credit_line" type="number" class="form-control" name="creditLine"
                               placeholder="输入担保金额"
                               required>

                        <div class="help-block with-errors"></div>
                    </div>

                    <div class="form-group">
                        <label class="control-label">录入时间:</label>
                        <div class="input-group date">
                            <div class="input-group-addon">
                                <i class="fa fa-calendar"></i>
                            </div>
                            <input type="text" name="inputTime" class="form-control pull-right date form_datetime" id="inputTime">
                        </div>
                    </div>
                    <div class="box-footer">
                        <button type="button" class="btn btn-info pull-right" id="submitAdd">保存</button>
                    </div>
                    </form>
                <form id="addForm" enctype="multipart/form-data" style="display:none;">
                    <div class="box box-danger">
                        <div class="box-header with-border">
                            <h3 class="box-title">初始资料上传</h3>
                        </div>
                        <div class="box-body panel">
                            <div class="form-group">
                                <label for="input-id1" class="col-sm-6 control-label" id="input-idP1Label"><span
                                        class="asterisk">*</span>身份证复印件:</label>
                                <label for="input-id1" class="col-sm-6 control-label" id="input-idC1Label"><span
                                        class="asterisk">*</span>企业营业执照（副本）:</label>
                                <input id="input-id1" name="input-id1" type="file"  required="required"
                                       data-show-caption="true" class="imagelimit">
                            </div>

                            <div class="form-group">
                                <label for="input-id2" class="col-sm-6 control-label" id="input-idP2Label"><span
                                        class="asterisk">*</span>户口本:</label>
                                <label for="input-id2" class="col-sm-6 control-label" id="input-idC2Label"><span
                                        class="asterisk">*</span>开户许可证:</label>
                                <input id="input-id2" name="input-id2" type="file" required="required"
                                       data-show-caption="true" class="imagelimit">
                            </div>

                            <div class="form-group">
                                <label for="input-id3" class="col-sm-6 control-label" id="input-idP3Label"><span
                                        class="asterisk">*</span>收入证明:</label>
                                <label for="input-id3" class="col-sm-6 control-label" id="input-idC3Label"><span
                                        class="asterisk">*</span>机构信用代码证:</label>
                                <input id="input-id3" name="input-id3" type="file" required="required"
                                       data-show-caption="true" class="imagelimit">
                            </div>

                            <div class="form-group">
                                <label for="input-id4" class="col-sm-6 control-label" id="input-idP4Label"><span
                                        class="asterisk">*</span>最新的个人征信:</label>
                                <label for="input-id4" class="col-sm-6 control-label" id="input-idC4Label"><span
                                        class="asterisk">*</span>法人身份证:</label>
                                <input id="input-id4" name="input-id4" type="file" required="required"
                                       data-show-caption="true" class="imagelimit">
                            </div>

                            <div class="form-group">
                                <label for="input-id5" class="col-sm-6 control-label" id="input-idP5Label"><span
                                        class="asterisk">*</span>结婚证或单身证明:</label>
                                <label for="input-id5" class="col-sm-6 control-label" id="input-idC5Label">法人征信:</label>
                                <input id="input-id5" name="input-id5" type="file" data-show-caption="true" class="imagelimit">
                            </div>

                            <div class="form-group">
                                <label for="input-id6" class="col-sm-6 control-label" id="input-idC6Label"><span
                                        class="asterisk">*</span>企业征信:</label>
                                <input id="input-id6" name="input-id6" type="file" required="required"
                                       data-show-caption="true" class="imagelimit">
                            </div>

                            <div class="form-group">
                                <label for="input-id7" class="col-sm-6 control-label" id="input-idC7Label">验资报告:</label>
                                <input id="input-id7" name="input-id7" type="file"
                                       data-show-caption="true" class="imagelimit">
                            </div>

                            <div class="form-group">
                                <label for="input-id8" class="col-sm-6 control-label" id="input-idC8Label"><span
                                        class="asterisk">*</span>公司章程:</label>
                                <input id="input-id8" name="input-id8" type="file" required="required"
                                       data-show-caption="true" class="imagelimit">
                            </div>

                            <div class="form-group">
                                <label for="input-id9" class="col-sm-6 control-label" id="input-idC9Label"><span
                                        class="asterisk">*</span>年度报表:</label>
                                <input id="input-id9" name="input-id9" type="file" required="required"
                                       data-show-caption="true" class="imagelimit">
                            </div>

                            <div class="form-group">
                                <label for="input-id10" class="col-sm-6 control-label" id="input-idC10Label"><span
                                        class="asterisk">*</span>月度报表:</label>
                                <input id="input-id10" name="input-id10" type="file" required="required"
                                       data-show-caption="true">
                            </div>

                            <div class="form-group">
                                <label for="input-id11" class="col-sm-6 control-label" id="input-idC11Label">增值税纳税申报表:</label>
                                <input id="input-id11" name="input-id11" type="file"
                                       data-show-caption="true" class="imagelimit">
                            </div>

                            <div class="form-group">
                                <label for="input-id12" class="col-sm-6 control-label" id="input-idC12Label">法人夫妻双方的结婚证或户口本:</label>
                                <input id="input-id12" name="input-id12" type="file"
                                       data-show-caption="true" class="imagelimit">
                            </div>

                            <div class="form-group">
                                <label for="input-id13" class="col-sm-6 control-label"
                                       id="input-idP13Label">近半年银行卡流水清单:</label>
                                <input id="input-id13" name="input-id13" type="file" data-show-caption="true" class="imagelimit">
                            </div>

                            <div class="addcailiao">
                                <button type="button" class="ht_in_jia btn  pull-right" >+ 新增材料</button>
                            </div>

                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal" id="closeId2">关闭</button>
                        <button type="button" class="btn btn-primary" id="submitImgAdd">
                            确定
                        </button>
                    </div>
                </form>

            </div>
            <div id="J_progress_label" style="display: none;position: absolute;width: 200px;height: 60px;text-align: center;line-height: 60px;top: 0;left: 0;right: 0;bottom: 0;border-radius:15px;margin: auto;box-shadow:0px 0px 5px #e5f9f2;background:#f63;z-index:999;color:white;">

            </div>
        </div>
    </div>
</div>

<!-- delete modal -->
<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="deleteSmallModalLabel">
    <div class="modal-dialog modal-sm" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="deleteSmallModalLabel">设置为休眠户</h4>
            </div>
            <div class="modal-body">
                确定要休眠企业名称为 <span class="records"></span> 的档案信息吗?

                <form id="deleteForm">
                    <div class="form-group">
                        <input type="hidden" id="dormanystatus" name="operateType" value="9" readonly required>
                        <label class="control-label">原因:</label>
                        <textarea autofocus class="form-control" name="comName" minlength="5"
                                  maxlength="300" placeholder="输入原因" required>
                        </textarea>

                        <div class="help-block with-errors"></div>
                    </div>
                </form>

            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" form="deleteForm" class="btn btn-primary"
                        data-action="{type:'submit',form:'#deleteForm',url:'<%=request.getContextPath()%>/dormant/checkStatus',after:'$.myAction.refreshTable'}">
                    确定
                </button>
            </div>
        </div>
    </div>
</div>

<%--bestReport modal--%>
<div class="modal fade" id="bestReportModal" tabindex="-1" role="dialog" aria-labelledby="bestReportLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="bestReportModalLabel">尽调信息上传</h4>
            </div>
            <div class="modal-body">
                <form id="bestReportForm" enctype="multipart/form-data">
                    <input type="hidden" id="bestReport_compay_id" name="id" readonly required>
                    <input type="hidden" id="no_status" name="operateType" value="11" readonly required>

                    <div class="box box-danger">
                        <div class="box-header with-border">
                            <h3 class="box-title">尽调资料上传</h3>
                        </div>
                        <div class="box-body">
                            <div class="row">
                                <div class="form-group">
                                    <label for="input-id21" class="col-sm-6 control-label"
                                           id="input-idC1Labe2l">尽调报告资料:</label>
                                    <input id="input-id21" name="input-id21" type="file" data-show-caption="true" class="imagelimit">
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" id="submitImgAdd1">
                    确定
                </button>
            </div>
            <div id="J_progress_label" style="display: none;position: absolute;width: 200px;height: 60px;text-align: center;line-height: 60px;top: 0;left: 0;right: 0;bottom: 0;border-radius:15px;margin: auto;box-shadow:0px 0px 5px #e5f9f2;background:#f63;z-index:999;color:white;">

            </div>
        </div>
    </div>
</div>

<%--UnscheduledReport modal--%>
<div class="modal fade" id="unscheduledReportModal" tabindex="-1" role="dialog" aria-labelledby="unscheduledReportLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="unscheduledReportLabel">不定期尽调报告上传</h4>
            </div>
            <div class="modal-body">
                <form id="unscheduledReportForm" enctype="multipart/form-data">
                    <input type="hidden" id="unscheduledReport_compay_id" name="id" readonly required>
                    <input type="hidden" id="unscheduledReport_status" name="operateType" value="16" readonly required>

                    <div class="box box-danger">
                        <div class="box-header with-border">
                            <h3 class="box-title">不定期尽调报告上传</h3>
                        </div>
                        <div class="box-body">
                            <div class="row">
                                <div class="form-group">
                                    <label for="input-id22" class="col-sm-6 control-label"
                                           id="input-idC1Labe22">不定期尽调报告:</label>
                                    <input id="input-id22" name="input-id22" type="file" data-show-caption="true" class="imagelimit">
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" id="submitImgAdd2">
                    确定
                </button>
            </div>
            <div id="J_progress_label" style="display: none;position: absolute;width: 200px;height: 60px;text-align: center;line-height: 60px;top: 0;left: 0;right: 0;bottom: 0;border-radius:15px;margin: auto;box-shadow:0px 0px 5px #e5f9f2;background:#f63;z-index:999;color:white;">

            </div>
        </div>
    </div>
</div>

<!-- cancelStorage modal -->
<div class="modal fade" id="cancelStorageModal" tabindex="-1" role="dialog" aria-labelledby="cancelStorageModalLabel">
    <div class="modal-dialog modal-sm" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="cancelStorageModalLabel">存档设置</h4>
            </div>
            <div class="modal-body">
                <form id="cancelStorageForm"></form>
                确定要企业名为 <span class="records"></span> 的档案取消存档吗?
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" form="cancelStorageForm" class="btn btn-primary"
                        data-action="{type:'submit',form:'#cancelStorageForm',url:'<%=request.getContextPath()%>/archives/checkStatus',after:'$.myAction.refreshTable'}">
                    确定
                </button>
            </div>
        </div>
    </div>
</div>

<!-- storage modal -->
<div class="modal fade" id="storageModal" tabindex="-1" role="dialog" aria-labelledby="storageModalLabel">
    <div class="modal-dialog modal-sm" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="storageModalLabel">存档设置</h4>
            </div>
            <div class="modal-body">
                <form id="storageForm">
                    <input type="hidden" id="storage_id" name="id" readonly required>
                    <input type="hidden" id="storageType" name="operateType"  readonly required>
                    确定要企业名为 <span class="records"></span> 的档案存档吗?
                    <div class="form-group">
                        <label class="control-label"><span class="asterisk">*</span>存档原因</label>
                        <textarea autofocus  class="form-control" name="remark" placeholder="存档原因"
                                  minlength="1" required/>
                        <div class="help-block with-errors"></div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" form="storageForm" class="btn btn-primary"
                        data-action="{type:'submit',form:'#storageForm',url:'<%=request.getContextPath()%>/archives/checkStatus',after:'$.myAction.refreshTable'}">
                    确定
                </button>
            </div>
        </div>
    </div>
</div>

<!-- cancelStorage modal -->
<div class="modal fade" id="cancelDormantModal" tabindex="-1" role="dialog" aria-labelledby="cancelDormantModalLabel">
    <div class="modal-dialog modal-sm" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="cancelDormantModalLabel">取消休眠设置</h4>
            </div>
            <div class="modal-body">
                <form id="cancelDormantForm"></form>
                确定要企业名为 <span class="records"></span> 的档案取消休眠吗?
            </div>
            <div class="form-group">
                <label class="control-label"><span class="asterisk">*</span>理由</label>
                        <textarea autofocus id="cancelRemark" class="form-control" name="remark" placeholder="申请取消休眠理由"
                                  minlength="1" required/>

                <div class="help-block with-errors"></div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" form="cancelDormantForm" class="btn btn-primary"
                        data-action="{type:'submit',form:'#cancelDormantForm',url:'<%=request.getContextPath()%>/dormant/checkStatus',after:'$.myAction.refreshTable'}">
                    确定
                </button>
            </div>
        </div>
    </div>
</div>

<!-- storage modal -->
<div class="modal fade" id="dormantModal" tabindex="-1" role="dialog" aria-labelledby="dormantModalLabel">
    <div class="modal-dialog modal-sm" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="dormantModalLabel">休眠设置</h4>
            </div>
            <div class="modal-body">
                确定要企业名为 <span class="records"></span> 的档案休眠吗?
                <form id="dormantForm">
                    <input type="hidden" id="dormant_id" name="id" readonly required>
                    <input type="hidden" id="dormant_status" name="operateType" value="9" readonly required>
                    <div class="form-group">
                        <label class="control-label"><span class="asterisk">*</span>休眠理由</label>
                        <textarea autofocus id="domart_name" class="form-control" name="remark" placeholder="休眠理由"
                                  minlength="1" required/>
                        <div class="help-block with-errors"></div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" form="dormantForm" class="btn btn-primary"
                        data-action="{type:'submit',form:'#dormantForm',url:'<%=request.getContextPath()%>/archives/checkStatus',after:'$.myAction.refreshTable'}">
                    确定
                </button>
            </div>
        </div>
    </div>
</div>

<!-- msgShow modal -->
<div class="modal fade" id="msgShowModal" tabindex="-1" role="dialog" aria-labelledby="historyModalLabel">
    <div class="modal-dialog modal-sm" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="historyModalLabel">驳回原因</h4>
            </div>
            <div class="modal-body">

                <div id="historyDiv"></div>

            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>

<!-- 休眠记录 -->
<div class="modal fade" id="msgDorShowModal" tabindex="-1" role="dialog" aria-labelledby="dorHistoryModalLabel">
    <div class="modal-dialog modal-sm" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="dorHistoryModalLabel">驳回原因</h4>
            </div>
            <div class="modal-body">

                <div id="dorHistoryDiv"></div>

            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>

<script>
    //Date picker
    $('#datepicker').datepicker({
        autoclose: true,
        format: 'yyyy-mm-dd',
        todayHighlight: 1
    })

    //非空校验
    function checkInput(selectI) {

        var checkFlag = true;
        $("#addCompanyInfo :input").each(function () {
            var name = $(this).attr("id");
            if (name == "submitAdd"||name=="creditLine") {

            } else {
                if ($(this).val() == "") {
                    alert($('label[for="' + name + '"]').text() + "不能为空");
                    checkFlag = false;
                    return checkFlag;
                }
            }
        });
        return checkFlag;
    }

    //企业信息保存
    $("#submitAdd").click(function () {
        var data = $("#addCompanyInfo").serialize();
        var objS = document.getElementById("comType");
        var selectI = objS.options[objS.selectedIndex].value;
        if (checkInput(selectI)) {
            $.ajax({
                type: 'post',
                url: '/company/saveCompanyInfo',
                cache: false,
                data: data,
                dataType: 'json',
                success: function (data) {
                    if (data.status == "0") {
                        if (selectI == "4") {
                            $("#input-idP1Label").attr("style", "display:none");
                            $("#input-idP2Label").attr("style", "display:none");
                            $("#input-idP3Label").attr("style", "display:none");
                            $("#input-idP4Label").attr("style", "display:none");
                            $("#input-idP5Label").attr("style", "display:none");
                            $("#input-idP13Label").attr("style", "display:none");
                            $("#input-id13").attr("style", "display:none");
                        } else {
                            $("#input-idC1Label").attr("style", "display:none");
                            $("#input-idC2Label").attr("style", "display:none");
                            $("#input-idC3Label").attr("style", "display:none");
                            $("#input-idC4Label").attr("style", "display:none");
                            $("#input-idC5Label").attr("style", "display:none");
                            $("#input-idC6Label").attr("style", "display:none");
                            $("#input-id6").attr("style", "display:none");
                            $("#input-idC7Label").attr("style", "display:none");
                            $("#input-id7").attr("style", "display:none");
                            $("#input-idC8Label").attr("style", "display:none");
                            $("#input-id8").attr("style", "display:none");
                            $("#input-idC9Label").attr("style", "display:none");
                            $("#input-id9").attr("style", "display:none");
                            $("#input-idC10Label").attr("style", "display:none");
                            $("#input-id10").attr("style", "display:none");
                            $("#input-idC11Label").attr("style", "display:none");
                            $("#input-id11").attr("style", "display:none");
                            $("#input-idC12Label").attr("style", "display:none");
                            $("#input-id12").attr("style", "display:none");
                        }

                        $("#addForm").attr("style", "display:block");
                        $("#compay_id").attr("value", data.id);
                        //企业信息置为只读
                        $("#addCompanyInfo :input").each(function () {
                            $(this).attr("readonly", "readonly");
                        });
                        $("#submitAdd").attr("disabled", "disabled");
                    }
                    alert(data.message);
                },
                error: function () {
                    alert("修改企业信息失败");
                }
            })
        }
    })


    //图片非空校验
    function checkImageInput() {

        var checkFlag = true;
        $("#addForm :input").each(function () {
            var type = $(this).attr("type");
            if (type == "file" && $(this).attr("style") != "display:none" && $(this).attr("required") == "required") {
                var name = $(this).attr("id");
                if ($(this).val() == "") {
                    $('label[for="' + name + '"]').each(function () {
                        if ($(this).attr("style") != "display:none") {
                            alert($(this).text() + "不能为空");
                            checkFlag = false;
                        }
                    });
                }
                return checkFlag;
            }
        });
        return checkFlag;
    }

    $("#submitImgAdd").click(function () {

        var totalSize=0;
        var sizeFlag=true;
        var flag=true;
        var id = $("#compay_id").val();
        if (checkImageInput()) {
            $("#submitImgAdd").attr("disabled", "disabled");
            var formData = new FormData();
            var strParms = "id=" + id;
            $("#addForm :input").each(function () {
                var type = $(this).attr("type");
                if (type == "file" && $(this).attr("style") != "display:none") {
                    var name = $(this).attr("id");
                    var label_name = "";
                    var filename = $(this)[0].files[0];
                    $('label[for="' + name + '"]').each(function () {
                        if ($(this).attr("style") != "display:none") {
                            label_name = $(this).text();
                        }
                    });

                    if (label_name == null || label_name == "") {
                        flag = false;
                    }

                    if (filename == null) {
                        strParms = strParms + "&" + encodeURI(encodeURI(label_name)) + "=";
                    } else {
                        formData.append(label_name, filename);
                        totalSize=totalSize+filename.size;
                    }

                }
            });

            if(totalSize>200*1024*1024){
                sizeFlag=false;
                alert("文件需小于200M");
                $("#submitImgAdd").removeAttr("disabled");
                return;
            }
            if(sizeFlag && flag) {
                var that = this;
                var loadnum = 0;
                var oldloaded = 0;
                $.ajax({
                    type: 'post',
                    url: '/company/saveCompanyUploadInfo?' + strParms,
                    cache: false,
                    data: formData,
                    contentType: false,
                    processData: false,
                    xhr: function () {
                        myXhr = $.ajaxSettings.xhr();
                        if (myXhr.upload) {
                            $(that).parents('.modal ').find('#J_progress_label').show();
                            myXhr.upload.addEventListener('progress', function (e) {
                                if (e.lengthComputable) {
                                    if (e.loaded != 0) {
                                        loadnum += Math.abs(e.loaded - oldloaded);
                                        console.log(e.loaded, loadnum, e.total);
                                        oldloaded = e.loaded;
                                    } else {
                                        oldloaded = 0;
                                    }

                                    var percent = Math.floor(loadnum / e.total * 100);
                                    if (percent <= 100) {
                                        $(that).parents('.modal ').find("#J_progress_label").html('已上传：' + percent + '%');
                                    }
                                    if (percent >= 100) {
                                        $(that).parents('.modal ').find("#J_progress_label").html('文件上传完毕，请等待处理...');
                                    }
                                }
                            }, false);
                        }
                        return myXhr;
                    },
                    success: function (data) {
                        $.myNotify.success(data.msg);
                        $("#addModal").modal('hide');
                        loadHref('#archives/archives_user');
                        $("div").removeClass("modal-backdrop");
                    },
                    error: function () {
                        $.myNotify.danger(data.msg);
                        $("#submitImgAdd").removeAttr("disabled");
                    }
                })
            }else if (!flag) {
                $(".submitImgAdd").removeAttr("disabled");
                alert("标题不能为空");
            }
        }
    })

    $("#closeId1").click(function(){
        $("#addModal").modal('hide');
        loadHref('#archives/archives_user');
        $("div").removeClass("modal-backdrop");
    })

    $("#closeId2").click(function(){
        $("#addModal").modal('hide');
        loadHref('#archives/archives_user');
        $("div").removeClass("modal-backdrop");
    })

    $("#submitImgAdd1").click(function () {

        var id = $("#bestReport_compay_id").val();
        var formData = new FormData();
        var totalSize=0;
        var sizeFlag=true;
        $("#submitImgAdd1").attr("disabled", "disabled");
        $("#bestReportForm :input").each(function () {

            var type = $(this).attr("type");
            var name = $(this).attr("id");
            if (type == "file") {
                var label_name = $('label[for="' + name + '"]').text();
                formData.append(label_name, $(this)[0].files[0]);
                totalSize=totalSize+$(this)[0].files[0].size;
            }
        });

        if(totalSize>200*1024*1024){
            sizeFlag=false;
            alert("文件需小于200M");
            $("#submitImgAdd1").removeAttr("disabled");
            return;
        }
        if(sizeFlag) {
            var that = this;
            var loadnum = 0;
            var oldloaded = 0;
            $.ajax({
                type: 'post',
                url: '/company/saveCompanyUploadInfo?id=' + id + '&operateType=11',
                cache: false,
                data: formData,
                contentType: false,
                processData: false,
                xhr: function () {
                    myXhr = $.ajaxSettings.xhr();
                    if (myXhr.upload) {
                        $(that).parents('.modal ').find('#J_progress_label').show();
                        myXhr.upload.addEventListener('progress', function (e) {
                            if (e.lengthComputable) {
                                if (e.loaded != 0) {
                                    loadnum += Math.abs(e.loaded - oldloaded);
                                    console.log(e.loaded, loadnum, e.total);
                                    oldloaded = e.loaded;
                                } else {
                                    oldloaded = 0;
                                }

                                var percent = Math.floor(loadnum / e.total * 100);
                                if (percent <= 100) {
                                    $(that).parents('.modal ').find("#J_progress_label").html('已上传：' + percent + '%');
                                }
                                if (percent >= 100) {
                                    $(that).parents('.modal ').find("#J_progress_label").html('文件上传完毕，请等待处理...');
                                }

                            }
                        }, false);
                    }
                    return myXhr;
                },
                success: function (data) {
                    alert(data.msg);
                    $("#bestReportModal").modal('hide');
                    window.location.reload();

                },
                error: function () {
                    alert("上传图片失败");
                    $("#submitImgAdd1").removeAttr("disabled");
                }
            })
        }
    })



    $("#submitImgAdd2").click(function () {

        var id = $("#unscheduledReport_compay_id").val();
        var formData = new FormData();
        var totalSize=0;
        var sizeFlag=true;
        $("#submitImgAdd2").attr("disabled", "disabled");
        $("#unscheduledReportForm :input").each(function () {

            var type = $(this).attr("type");
            var name = $(this).attr("id");
            if (type == "file") {
                var label_name = $('label[for="' + name + '"]').text();
                formData.append(label_name, $(this)[0].files[0]);
                totalSize=totalSize+$(this)[0].files[0].size;
            }
        });
        if(totalSize>200*1024*1024){
            sizeFlag=false;
            alert("文件需小于200M");
            $("#submitImgAdd2").removeAttr("disabled");
            return;
        }
        if(sizeFlag) {
            var that = this;
            var loadnum = 0;
            var oldloaded = 0;

            $.ajax({
                type: 'post',
                url: '/company/saveCompanyUploadInfo?id=' + id,
                cache: false,
                data: formData,
                contentType: false,
                processData: false,
                xhr: function () {
                    myXhr = $.ajaxSettings.xhr();
                    if (myXhr.upload) {
                        $(that).parents('.modal ').find('#J_progress_label').show();
                        myXhr.upload.addEventListener('progress', function (e) {
                            if (e.lengthComputable) {
                                if (e.loaded != 0) {
                                    loadnum += Math.abs(e.loaded - oldloaded);
                                    console.log(e.loaded, loadnum, e.total);
                                    oldloaded = e.loaded;
                                } else {
                                    oldloaded = 0;
                                }

                                var percent = Math.floor(loadnum / e.total * 100);
                                if (percent <= 100) {
                                    $(that).parents('.modal ').find("#J_progress_label").html('已上传：' + percent + '%');
                                }
                                if (percent >= 100) {
                                    $(that).parents('.modal ').find("#J_progress_label").html('文件上传完毕，请等待处理...');
                                }
                            }
                        }, false);
                    }
                    return myXhr;
                },
                success: function (data) {
                    alert('上传图片成功');
                    $("#bestReportModal").modal('hide');
                    window.location.reload();

                },
                error: function () {
                    alert("上传图片失败");
                    $("#submitImgAdd2").removeAttr("disabled");
                }
            })
        }
    })


    function comTypeChange() {
        var objS = document.getElementById("comType");
        var selectI = objS.options[objS.selectedIndex].value;

    }

    var $table = $('#table');

    $(function () {
        $table.bootstrapTable({
            url: path + '/archives/list',
            idField: 'id',
            searchOnEnterKey: false,
            showColumns: false,
            detailView: false,
            search: false,
            striped: true,
            //queryParams: Search,
            pagination: true,

            //得到查询的参数
            queryParams : function (params) {
                //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                var temp = {
                    limit: params.limit,                         //页面大小
                    offset: params.offset,   //页码
                   // sort: params.sort,      //排序列名
                    order: params.order, //排位命令（desc，asc）
                    comName: $("#comName_id").val(),
                    comType: $("#comType_id").val(),
                    status: $("#status_id").val(),
                    inputTime: $("#datepicker").val()
                };
                return temp;
            },
            columns: [
                {field: 'id', title: 'ID'},
                {field: 'comName', title: '企业名称'},
                {field: 'businessCode', title: '营业执照编号（身份证号）'},
                {field: 'creditLine', title: '授信额度'},
                {field: 'creditLimit', title: '授信期限'},
                {
                    field: 'comType', title: '类别', formatter: function (value, row, index) {
                    if (value == 1) {
                        return "核心企业"
                    } else if (value == 2) {
                        return "一般企业"
                    } else if (value == 3) {
                        return "个人"
                    }else if (value == 0) {
                        return "其他"
                    }
                }
                },
                {
                    field: 'businessType', title: '业务品种', formatter: function (value, row, index) {
                    if (value == 1) {
                        return "供应链融资"
                    } else if (value == 2) {
                        return "企业经营贷"
                    } else if (value == 3) {
                        return "个人借款"
                    }
                }
                },
                {
                    field: 'status', title: '所处阶段', formatter: function (value, row, index) {
                    if (value == 1) {
                        if(row.msgCount>0){
                            return "<a href='javascript:;' onclick='showMsgDetail("+row.id+")'>待尽调<sup style='color: red'>"+row.msgCount+"</sup></a>";
                        }else{
                            return "待尽调"
                        }
                    } else if (value == 2) {
                        if(row.msgCount>0){
                            return "<a href='javascript:;' onclick='showMsgDetail("+row.id+")'>待部门审核<sup style='color: red'>"+row.msgCount+"</sup></a>";
                        }else{
                            return "待部门审核"
                        }
                    } else if (value == 3) {
                        if(row.msgCount>0){
                            return "<a href='javascript:;' onclick='showMsgDetail("+row.id+")'>待风控审核<sup style='color: red'>"+row.msgCount+"</sup></a>";
                        }else{
                            return "待风控审核"
                        }
                    } else if (value == 4) {
                        return "待上线"
                    } else if (value == 5) {
                        return "贷后管理"
                    } else if (value == 6) {
                        return "存档"
                    }
                }
                },
                {
                    field: 'dormant', title: '休眠状态', formatter: function (value, row, index) {
                    if (value == 1) {
                        if(row.dormanyCount>0){
                            return "<a href='javascript:;' onclick='showDorMsgDetail("+row.id+")'>正常<sup style='color: red'>"+row.dormanyCount+"</sup></a>";
                        }else{
                            return "正常"
                        }
                    } else if (value == 2) {
                        return "待休眠"
                    } else if (value == 3) {
                        return "休眠"
                    } else if (value == 4) {
                        return "待正常"
                    }
                }
                },
                {field: 'inputTime', title: '录入时间'},
                {field: 'activeTime', title: '激活时间'},
                {field: 'upTime', title: '上线时间'},
                /*{field: 'supportId', title: '担保方信息'},*/
                {
                    field: 'action',
                    title: '操作',
                    halign: 'center',
                    align: 'left',
                    formatter: 'actionFormatter',
                    events: 'actionEvents',
                    width: 600,
                    clickToSelect: false
                }
            ]
        });
    });
    //参数传递
    function Search() {
        var temp = {
            comName: $("#comName_id").val()
            /*pageSize: 10,
            sortOrder: "asc",
            pageNumber:1,*/
           /* reallyName: $("#reallyName").val(),*/
        };
        return temp;
    }
    //查询
    $(document).on('click', ".queryButton",function(){
        $('#table').bootstrapTable('refresh');
    });
    // 数据表格展开内容
    function detailFormatter(index, row) {
        var html = [];
        $.each(row, function (key, value) {
            html.push('<p><b>' + key + ':</b> ' + value + '</p>');
        });
        return html.join('');
    }

    function editAfter(obj, row) {
        $('#editForm')
        $(".chosen-select").trigger("chosen:updated");
    }

    function actionFormatter(value, row, index) {
        str = '\
            <button class="detail ml10 btn btn-primary" >详情</button>　\
        ';
        if(row.status==1){
            str+='\
            <button class="add ml10 btn btn-primary">添加担保方</button>　\
            <button class="bestReport  ml10 btn btn-primary" data-toggle="tooltip" >上传尽调报告</button>　\
            ';
        }
        if (row.status == 5) {
            str += '\
            <button class="unscheduledReport ml10 btn btn-primary" data-toggle="tooltip" >上传不定期尽调报告</button>　\
            <button class="storage ml10 btn btn-primary" data-toggle="tooltip" >存档</button>　\
            ';
        }
        if (row.status == 6) {
            str += '\
            <button class="cancelStorage ml10 btn btn-primary" data-toggle="tooltip" >取消存档</button>　\
            ';
        }
        if(row.dormant==1){
            str += '\
            <button class="dormant ml10 btn btn-primary" data-toggle="tooltip" >休眠</button>　\
            ';
        }
        /*str += '\
            <button class="history ml10 btn btn-primary" data-toggle="tooltip" >历史记录</button>　\
            ';*/
        return str;
    }

    window.actionEvents = {
        'click .edit': function (e, value, row, index) {
            $('#editModal').modal('show')
            $('#editForm').fillForm(row);

            editAfter('', row);
        },
        'click .remove': function (e, value, row, index) {
            $('#deleteModal').modal('show');
            $('.records').html(row.comName);
            var html = '';
            html += '<input type="hidden" name="id" value="' + row.id + '">';
            html += '<label class="control-label" for="comName">原因:</label>';
            html += '<textarea autofocus class="form-control" name="comName" minlength="5" maxlength="300" placeholder="输入原因" required>';
            $('#deleteForm').html(html);
        },
        'click .add': function (e, value, row, index) {
           /* $('#addModal').modal({backdrop: 'static', keyboard: false});*/
    $('#addModal').modal('show');
            //$('#allotForm').fillForm(row);
            $('#compay_id').val(row.id)
            /* $('.records').html(row.reallyName);
             var html = '';
             html += '<input type="hidden" name="id" value="' + row.id+ '">';
             $('#deleteForm').html(html);*/
        },
        'click .detail': function (e, value, row, index) {
            var id = row.id
            $.myAdmin.loadContent('#archives/detail?id=' + id + '');
        },
        'click .bestReport': function (e, value, row, index) {
            $('#bestReportModal').modal('show');
            $('#bestReport_compay_id').val(row.id)
        },
        'click .unscheduledReport': function (e, value, row, index) {
            $('#unscheduledReportModal').modal('show');
            $('#unscheduledReport_compay_id').val(row.id)
        },
        'click .storage': function (e, value, row, index) {
            $('#storageModal').modal('show');
            $('.records').html(row.comName);
            $('#storage_id').val(row.id);
            $('#storageType').val(7);
            /*var html = '';
            html += '<input type="hidden" name="id" value="' + row.id + '">';
            html += '<input type="hidden" name="operateType" value="7">';
            $('#storageForm').html(html);*/
        },
        'click .cancelStorage': function (e, value, row, index) {
            $('#cancelStorageModal').modal('show');
            $('.records').html(row.comName);
            var html = '';
            html += '<input type="hidden" name="id" value="' + row.id + '">';
            html += '<input type="hidden" name="operateType" value="8">';
            $('#cancelStorageForm').html(html);
        },
        'click .dormant': function (e, value, row, index) {
            $('#dormantModal').modal('show');
            $('.records').html(row.comName);
            $('#dormant_id').val(row.id);
        },
        'click .cancelDormant': function (e, value, row, index) {
            $('#cancelDormantModal').modal('show');
            $('.records').html(row.comName);
            var html = '';
            html += '<input type="hidden" name="id" value="' + row.id + '">';
            html += '<input type="hidden" name="operateType" value="10">';
            $('#cancelDormantForm').html(html);
        },'click .history': function (e, value, row, index) {
            var id = row.id
            $.myAdmin.loadContent('#archives/historyLoad?id=' + id + '');
        }
    };
    var setting = {
        view: {
            dblClickExpand: false
        },
        data: {
            simpleData: {
                enable: true
            }
        }
//        callback: {
//            onClick: onClick
//        }
    };

    function showMsgDetail(row){
        $.ajax({
            type : "post",
            url : "/archives/approvalRecordList?id="+row,
            async : false,
            success : function(data){
                if (data.status != 0){
                    alert(data.msg);
                }else {
                    $("#msgShowModal").modal('show');
                    var list = [];
                    list = data.msglist;
                    listlength = list.length;
                    var detailHtml = '<tr><th style="width:200px;">原因</th><th style="width:260px;">时间</th></tr>';
                    for (var i = 0; i < list.length; i++) {
                        var demo = list[i].demo;
                        var operateTime = list[i].operateTime;
                        if(operateTime==""||operateTime==null||operateTime=="null"){
                            operateTime="-";
                        }

                        detailHtml += '<tr>';
                        detailHtml += '<td class="txt_c" style="width:200px">'+ demo +'</td>';
                        detailHtml += '<td class="c_blue txt_c" style="width:260px">'+ operateTime +'</td>';
                        detailHtml += '</tr>';
                    }
                    $("#historyDiv").html(detailHtml);
                }


            }
        });
    }

    function showDorMsgDetail(row){
        $.ajax({
            type : "post",
            url : "/archives/dormanyRecordList?id="+row,
            async : false,
            success : function(data){
                if (data.status != 0){
                    alert(data.msg);
                }else {
                    $("#msgDorShowModal").modal('show');
                    var list = [];
                    list = data.msglist;
                    listlength = list.length;
                    var detailHtml = '<tr><th style="width:200px;">原因</th><th style="width:260px;">时间</th></tr>';
                    for (var i = 0; i < list.length; i++) {
                        var demo = list[i].demo;
                        var operateTime = list[i].operateTime;
                        if(operateTime==""||operateTime==null||operateTime=="null"){
                            operateTime="-";
                        }

                        detailHtml += '<tr>';
                        detailHtml += '<td class="txt_c" style="width:200px">'+ demo +'</td>';
                        detailHtml += '<td class="c_blue txt_c" style="width:260px">'+ operateTime +'</td>';
                        detailHtml += '</tr>';
                    }
                    $("#dorHistoryDiv").html(detailHtml);
                }


            }
        });
    }

    $("#bestReportModal").on("hidden.bs.modal", function() {
        $(this).removeData("bs.modal");
    });

    $(function () {
        var inputidnum=31;
        $('.panel').on('click', '.ht_in_jia', function () {
            inputidnum++;
            var thisid="input-id"+inputidnum;
            var thisidLabel = "input-id"+inputidnum+"Label";

            $('.panel').on('input propertychange','.inputtitle',function () {
                $(this).parent().next('label').html('用户新增'+$(this).val());
            });
            $('.panel').on('click','.ht_in_jian',function () {
                $(this).parents('.form-group').remove();
            });

            $('.panel').append('<div class="form-group">\n' +
                    '<span class="formspan col-sm-6">标题：<input type="text" name="" class="inputtitle"/></span><label for="'+thisid+'" class="col-sm-6 control-label" style="display: none;" id="'+thisidLabel+'"></label>' +
                    '<input id="'+thisid+'" name="'+thisid+'" type="file" data-show-caption="true" class="imagelimit">' +
                    '<input type="button" value="-" class="ht_in_jian">' +
                    '</div>');



        });

    })

    $(".imagelimit").change(function(){
        var file = $(this)[0].files[0];
        if(file !=null && file!=undefined && file !="") {
            console.log(file.name);
            console.log(file.name.indexOf(".jpg"));
            var name=file.name.toLowerCase();
            if (name.indexOf(".png") > 0 ||name.indexOf(".jpg") > 0 ||name.indexOf(".pdf") > 0 || name.indexOf(".rar") > 0 || name.indexOf(".zip") > 0 || name.indexOf(".jpeg") > 0 || name.indexOf(".gif") > 0 || name.indexOf(".bmp") > 0) {
            } else {
                alert("文件类型不支持");
                $(this).val("");
            }
        }
    })

    $('.form_datetime').datetimepicker({
        locale: 'zh-CN',
        language: 'zh-CN',
        format: "yyyy-mm-dd hh:ii:ss",
        sideBySide: true
    });

</script>